﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Async MVC4 Controller with ASP.NET Session</title>
    <script src="Scripts/jquery-2.0.2.min.js"></script>
    <style>
        body
        {
            font-family: 'Arial';
            font-size: medium;
        }
    </style>
</head>
<body>
    @*Author: Otto Neff | webapps-in-action.com*@
    <a href="home/login">login</a><br />
    calling every 5 seconds again all asyncs
    <ul id="asynResult">
    </ul>
    <script>
        var callGroup = 0;
        $(function () {
            doAsyncs();
            setInterval("doAsyncs()", (1000 * 5)); // every 5secs
        });
        function doAsyncs() {
            $("#asynResult").prepend("<li><b>Calling another group</b> " + new Date());
            callGroup++;
            $([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).each(function () {
                var number = this;
                $.getJSON("/GetInfo/Async/" + number + "-" + callGroup, function (data) {
                    returnTime = new Date();
                    if (data.guid == null) {
                        $("#asynResult").prepend("<li>Call " + number + "-" + callGroup + " - Error: <b>" + data + "</b> returned " + returnTime + ":" + returnTime.getTime() + "</li>");
                    } else {
                        $("#asynResult").prepend("<li>Call " + data.callId +
                            " - ObjectTime UTC <b>" + data.dateTimeUtc + "</b> - " +
                            "- Money: " + data.money +
                            "- Text: " + data.text +
                            "- Guid: " + data.guid +
                            "- delayed by <b>" + data.delayed + "ms</b></li>");
                    }
                });
            });
        }
    </script>
</body>
</html>
